<template>
  <div class="clientType">
    <div class="title-container">
      <div class="left-box">
        <el-form ref="form" :model="searchForm" :inline="true" class="formClass">
          <el-form-item>
            <el-input
              prefix-icon="el-icon-search"
              type="input"
              placeholder="请输入公司名称"
              v-model="searchForm.companyName"
              style="margin-right: 10px;"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="searchClick">搜索</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <global-card>
      <template #leftTitle>
        <el-button type="success" icon="el-icon-refresh" @click="refresh">刷新</el-button>
      </template>
      <template #content>
        <el-table
          v-loading="loading"
            :data="tableData"
        border
        style="width: 100%"
        class="elTable"
        >
          <el-table-column type="index" label="序号" width="80" align="center"/>
          <el-table-column prop="companyName" label="客户编码" align="center"/>
          <el-table-column prop="companyName" label="客户名称" align="center"/>
          <el-table-column prop="companyName" label="客户手机号" align="center"/>
          <el-table-column prop="companyName" label="充值金额" align="center"/>
          <el-table-column prop="companyName" label="充值时间" align="center"/>
          <el-table-column label="操作" width="120" align="center">
            <template #default="{ row }">
              <perButton label="审核" type="primary" icon="el-icon-plus" perms="PROTOCOL_ADD"
                         @click="examineClick"></perButton>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template #footer>
        <pagination
          class="pagination"
          :total="count"
          :page.sync="pageIndex"
          :limit.sync="pageSize"
          @pagination="pagination"
        />
      </template>
    </global-card>

    <global-message
      v-if="isGlobalMessageShow"
      @receive="receive"
      :message="message"
    />
  </div>
</template>

<script>
  import perButton from "@/components/permissionButton"
  import {
    queryCompanyPage,
    queryCompanyList,
    insertCompanyPage,
    updateCompanyPage
  } from "@/api/corporationMessage/corporationInfo"
  import { queryAccountList } from "@/api/appUserControl/account"

  export default {
    components: {
      perButton
    },
    data() {
      return {
        tableData: [],
        pageIndex: 1,
        pageSize: 10,
        count: 0,
        searchForm: {
          agreementName: "",
          agreementType: ""
        },

        detailsDisabled: false,
        isGlobalMessageShow: false,

        dialogCenterTitle: "",
        dialogTitle: "",
        message: "",

        loading: false,
        addOrUpdateLoading: false
      }
    },
    created() {
      this.getData()
    },
    methods: {
      async searchClick() {
        await this.getData()
      },
      async getData() {
        const { agreementName, agreementType } = this.searchForm
        this.loading = true
        const data = await queryCompanyPage({
          pageIndex: this.pageIndex,
          pageSize: this.pageSize,
          agreementName: agreementName,
          agreementType: agreementType
        })
        this.tableData = data.object.data
        this.count = data.object.count
        this.loading = false
      },
      pagination(pageItem) {
        this.getData(pageItem.page, pageItem.limit)
      },

      // 审核
      examineClick() {
        this.dialogCenterTitle = "新建公司"
        this.dialogTitle = "新建公司"

        this.queryAccountList()

        Object.keys(this.newCompanyModel).forEach((item) => {
          this.newCompanyModel[item] = ""
        })

        this.detailsDisabled = false
        this.addOrUpdateLoading = false
        this.$refs.ycDialog.dialogVisible = true
      },

      async dialogSave() {
        this.$refs.agreementModelRef.validate(async (v) => {
          if (v) {
            this.addOrUpdateLoading = true
              const { status, message } = await insertCompanyPage({ ...this.newCompanyModel })
              if (status == "200") {
                this.$message({
                  message: message,
                  type: "success"
                })
                this.getData()
                this.$refs.ycDialog.dialogVisible = false
              }
            this.addOrUpdateLoading = false
          }
        })
      },

      receive() {
        this.isGlobalMessageShow = false
      },

      refresh() {
        this.searchForm = {
          agreementName: "",
          agreementType: ""
        }
        this.getData()
      }
    }
  }
</script>

<style lang="scss" scoped>
  .clientType {
    .title-container {
      display: flex;
      justify-content: flex-end;
      margin-right: 20px;

      .left-box {
        display: flex;

        .formClass {
          /*display: flex;*/
          /*margin-right: 20px;*/

          .el-form-item {
            margin-top: 20px;
            margin-bottom: 0;

            .el-input {
              width: 216px;
            }

            .el-select {
              width: 171px;
              margin-left: 10px;
            }

            .el-date-editor {
              width: 336px;
              margin-left: 10px;
            }
          }
        }

        /*.el-button {*/
        /*  // width: 42px;*/
        /*  height: 36px;*/
        /*  margin-top: 20px;*/
        /*}*/
      }
    }
  }
</style>
